# coding:utf-8

"""
error类
"""


class QAError_fetch_data(RuntimeError):
    def __init__(self, res):
        RuntimeError.__init__(self, 'QA FETCH DATA ERROR', res)


class QAError_no_data_in_database(RuntimeError):
    def __init__(self, res):
        RuntimeError.__init__(self, 'QA FETCH NO DATA ERROR', res)


class QAError_crawl_data_web(RuntimeError):
    def __init__(self, res):
        RuntimeError.__init__(self, 'QA CRAWLER ERROR', res)


class QAError_database_connection(RuntimeError):
    def __init__(self, res):
        RuntimeError.__init__(self, 'QA DATABASE CONNECTION ERROR', res)


class QAError_web_connection(RuntimeError):
    def __init__(self, res):
        RuntimeError.__init__(self, 'QA WEB CONNECTION ERROR', res)


class QAError_market_enging_down(RuntimeError):
    def __init__(self, res):
        RuntimeError.__init__(self, 'QA MARKET ENGING DOWN ERROR', res)


# 4开头的错误是用户输入的入参缺失或格式不对，需要在前端页面展示给用户错误原因
ERR_U_1 = 4001  # 参数缺失
ERR_U_2 = 4002  # 参数值校验失败

# 5开头的错误是服务器端在计算接口的数据时发生的错误，不需要在前端页面展示，主要是为了给开发对接的同事看，方便快速定位问题
ERR_S_1 = 5001  # 易鑫的组合数据接口报错，无法返回数据
ERR_S_2 = 5002  # 取基金、指数、组合等的净值或收益率时没有取到数据

# 错误码为-1的错误，是之前代码中没有考虑到的bug，需要修改代码
ERR_OTHER = -1


# 捕获用户入参的错误
class FOFUserError(Exception):
    def __init__(self, err_code, msg):
        Exception.__init__(self)
        self.err_code = err_code
        self.msg = msg

    def __str__(self):
        return f'{self.err_code} => {self.msg}'


# 捕获服务器的错误
class FOFServerError(Exception):
    def __init__(self, err_code, msg):
        Exception.__init__(self)
        self.err_code = err_code
        self.msg = msg

    def __str__(self):
        return f'{self.err_code} => {self.msg}'
